package com.jyh.homework;

import java.util.ArrayList;

public class HomeWork1 {
    public static void main(String[] args) {
        //定义集合
        ArrayList arrayList = new ArrayList();
        //添加数据
        arrayList.add("孙悟空");
        arrayList.add("猪八戒");
        arrayList.add("沙和尚");
        arrayList.add("铁扇公主");
        //打印集合
        System.out.println(arrayList);
        //arrayList.get()获取指定索引位置元素
        Object o = arrayList.get(3);
        System.out.println("第4个元素是: " + o);
        //打印集合大小
        System.out.println("集合大小为:" + arrayList.size());
        //删除元素"铁扇公主"
        arrayList.remove("铁扇公主");
        System.out.println(arrayList);
        //删除第3个元素
        arrayList.remove(2);
        System.out.println(arrayList);
        //及那个元素"猪八戒"改为"猪悟能"
        arrayList.set(1,"猪悟能");
        //打印集合
        System.out.println(arrayList);

    }
}
